
from flask import g,session,request,render_template

class Fhook():
    @staticmethod
    def flaskhook(app):
        
        @app.before_request
        def usrstat():
            e="你家cookie咋了？"
            if 'username' in session and 'rid' in session:      
                if 'username' in request.cookies :
                    if (request.cookies.get('username')==session['username']):
                        g.username=str(session['username'])
                        g.rid=int(session['rid'])
                        g.uid=int(session['uid'])

                    else:
                        session.clear()
                        g.username=None
                        return render_template('cookierror.html',errortext=e)
                    
                else:
                    session.clear()
                    g.username=None
                    return render_template('cookierror.html',errortext=e)
                        
                    
                    
            else:
                g.username=None